<?php
define('DEBUG', true);
DEBUG?error_reporting(32767):error_reporting(0);
date_default_timezone_set("Asia/Shanghai");

header( "Content-type: text/html; charset=utf-8" );
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );

define('IN_JOSEPPE', true);
define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);

$_SGLOBAL = $_SCONFIG = $_SCOOKIE = $_SN = $_SC = array();

include_once S_ROOT.'./config.php';
include_once S_ROOT.'./source/function_common.php';
include_once S_ROOT.'./source/function_sujie.php';

//时间
$mtime = explode(' ', microtime());
$_SGLOBAL['timestamp'] = $mtime[1];
$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];
$beginday = mktime(0,0,0,2,14,2011);

//GPC过滤*********给GET，POST加反斜杆
$magic_quote = get_magic_quotes_gpc();
if(empty($magic_quote)) {
	$_GET = saddslashes($_GET);
	$_POST = saddslashes($_POST);
	$_REQUEST = saddslashes($_REQUEST);
}

//链接数据库
dbconnect();

//COOKIE
$prelength = strlen($_SC['cookiepre']);
foreach($_COOKIE as $key => $val) {
	if(substr($key, 0, $prelength) == $_SC['cookiepre']) {
		$_SCOOKIE[(substr($key, $prelength))] = empty($magic_quote) ? saddslashes($val) : $val;
	}
}

//启用GIP
if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) {
	ob_start('ob_gzhandler');
} else {
	ob_start();
}

//初始化系统参数
$_SCONFIG['pagesize'] = 8; //默认分页大小

//处理REQUEST_URI
if(!isset($_SERVER['REQUEST_URI'])) {
	$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
	if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
if($_SERVER['REQUEST_URI']) {
	$temp = urldecode($_SERVER['REQUEST_URI']);
	if(strexists($temp, '<') || strexists($temp, '"')) {
		$_GET = shtmlspecialchars($_GET);//XSS*******去掉html代码
	}
}

//读取设置
$arrs = $_SGLOBAL['db']->fetch_all("select `name`, `value` from ".tname("setting"));
foreach($arrs as $arr){
	if($arr['name'] == 'logomade' || $arr['name'] == 'technics'){
		$$arr['name'] = unserialize($arr['value']);
	} else {
		$setting[$arr['name']] = $arr['value'];
	}
}
$arrs = $_SGLOBAL['db']->fetch_all("select * from ".tname("product_type"));
foreach($arrs as $arr){
	if($arr['rootid'] == 0){
		$types[] = $arr;
		foreach($arrs as $arra){
			if($arra['rootid'] == $arr['id']){
				$types[] = $arra;
			}
		}
	}
}

$where = isset($_GET['tid'])?" and typeid='$_GET[tid]'":"";
$product = $_SGLOBAL['db']->fetch_all("select * from ".tname("product")." where 1 $where order by indexnum");
foreach($product as $key => $p){
	$product[$key]['img'] = $_SGLOBAL['db']->fetch_all("select * from ".tname("product_img")." where pid=$p[id]");
}

